package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.GoodsQo;
import com.qf.staff.common.vo.GoodsVo;
import com.qf.staff.service.GoodsService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "商品管理Api")
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    GoodsService goodsService;

    @ApiOperation("查询所有商品信息")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "page", value = "页码"),
                    @ApiImplicitParam(name = "size", value = "条数"),
                    @ApiImplicitParam(name = "goodsName", value = "商品名")
            })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<GoodsVo>> list(@RequestParam(defaultValue = "1") int page,
                                           @RequestParam(defaultValue = "10") int size,
                                           GoodsQo goodsQo) {
        return RespResult.success(goodsService.list(page, size, goodsQo));
    }

    @ApiOperation("根据id修改status为0是删除商品信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "goodsId", value = "商品id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete")
    public RespResult<Integer> remove(GoodsQo goodsQo) {
        return RespResult.success(goodsService.remove(goodsQo));
    }


    @ApiOperation("根据ID修改商品信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "goodsId", value = "商品id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(GoodsQo goodsQo) {
        return RespResult.success(goodsService.modify(goodsQo));
    }

    @ApiOperation("根据id修改status为0是批量删除商品信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete/all/{status}")
    public int deleteAll(@RequestBody List<Integer> ids, @PathVariable("status") int status) {
        return goodsService.removeAll(ids, status);
    }

    @ApiOperation("添加商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsName", value = "商品名"),
            @ApiImplicitParam(name = "goodsBrand", value = "商品品牌"),
            @ApiImplicitParam(name = "categoryId", value = "上级"),
            @ApiImplicitParam(name = "file", value = "头像"),
            @ApiImplicitParam(name = "price", value = "商品价格"),
            @ApiImplicitParam(name = "status", value = "状态")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(GoodsQo goodsQo, MultipartFile file) {
        return RespResult.success(goodsService.add(goodsQo, file));
    }

}
